const path = require('path')
const {appendFileSync, existsSync, mkdirSync} = require('fs')

window.GetDocPath = function (fileName) {
    let dir = path.join(window.utools.getPath('documents'), "todoNotes")
    if (!existsSync(dir)) {
        mkdirSync(dir)
    }

    return path.join(dir, fileName)
}

window.writeFile = function (msg, startTime, fileName) {
    try {
        let endTime = (new Date()).toLocaleString()
        let data = {
            "msg": msg,
            "start_time": startTime,
            "end_time": endTime,
            "spend_second": ((new Date(endTime)).getTime() - (new Date(startTime)).getTime()) / 1000
        }

        let filePath = GetDocPath(fileName)
        console.log(filePath);

        appendFileSync(filePath, endTime + "---" + JSON.stringify(data) + "\r\n", 'utf-8')
    } catch (e) {
        console.log(e);
    }
}
